// share
const login = r => require.ensure([], () => r(require('@/views/login/login')), 'login')
const NotFound = r => require.ensure([], () => r(require('@/views/_share/404')), '404')
const layout = r => require.ensure([], () => r(require('@/views/_share/layout')), 'layout')

// router-view
const dashboard = r => require.ensure([], () => r(require('@/views/dashboard/dashboard')), 'dashboard')
const image = r => require.ensure([], () => r(require('@/views/imageContent/image')), 'image')
const addimg = r => require.ensure([], () => r(require('@/views/imageContent/addimg')), 'addimg')
const pot = r => require.ensure([], () => r(require('@/views/placeOrderTime/pot')), 'pot')
const feedback = r => require.ensure([], () => r(require('@/views/feedback/feedback')), 'feedback')
const order = r => require.ensure([], () => r(require('@/views/order/order')), 'order')
const user = r => require.ensure([], () => r(require('@/views/user/user')), 'user')
const month = r => require.ensure([], () => r(require('@/views/vip/month')), 'month')
const vip = r => require.ensure([], () => r(require('@/views/vip/vip')), 'month')
const ticket = r => require.ensure([], () => r(require('@/views/ticket/ticket')), 'ticket')
const notice = r => require.ensure([], () => r(require('@/views/notice/notice')), 'notice')
const addnotice = r => require.ensure([], () => r(require('@/views/notice/addnotice')), 'addnotice')
const act = r => require.ensure([], () => r(require('@/views/act/act')), 'act')
const addact = r => require.ensure([], () => r(require('@/views/act/addact')), 'addact')

export default [
  {
    path: '/login',
    name: 'login',
    component: login,
    beforeEnter: (to, from, next) => {
      var storage = window.localStorage
      if (storage.getItem('token') && storage.getItem('admin')) {
        next({ name: 'dashboard' })
      } else {
        next()
      }
    },
    hidden: true
  },
  {
    path: '/404',
    name: 'NotFound',
    component: NotFound,
    hidden: true
  },
  {
    path: '/',
    component: layout,
    name: 'root',
    iconCls: 'el-icon-message',
    redirect: { name: 'dashboard' }, // 默认子路由
    children: [
      { path: '/dashboard', component: dashboard, name: 'dashboard', meta: { requireAuth: true } },
      { path: '/image', component: image, name: 'image', meta: { requireAuth: true } },
      { path: '/image/addimg', component: addimg, name: 'addimg', meta: { requireAuth: true } },
      { path: '/pot', component: pot, name: 'pot', meta: { requireAuth: true } },
      { path: '/feedback', component: feedback, name: 'feedback', meta: { requireAuth: true } },
      { path: '/order', component: order, name: 'order', meta: { requireAuth: true } },
      { path: '/user', component: user, name: 'user', meta: { requireAuth: true } },
      { path: '/month', component: month, name: 'month', meta: { requireAuth: true } },
      { path: '/vip', component: vip, name: 'vip', meta: { requireAuth: true } },
      { path: '/ticket', component: ticket, name: 'ticket', meta: { requireAuth: true } },
      { path: '/notice', component: notice, name: 'notice', meta: { requireAuth: true } },
      { path: '/notice/add', component: addnotice, name: 'addnotice', meta: { requireAuth: true } },
      { path: '/act', component: act, name: 'act', meta: { requireAuth: true } },
      { path: '/act/add', component: addact, name: 'addact', meta: { requireAuth: true } }
    ]
  },
  {
    path: '*',
    redirect: { name: 'dashboard' } // 默认路由
  }
]
